package com.googlecode.rjm.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.googlecode.rjm.model.enumerations.Activity;

@Entity
@Table(name = "time_entries")
public class SpentTime extends Persistent implements Comparable<SpentTime> {
	
	private static final long serialVersionUID = 8824634223113507725L;

	@Id
	private Integer id;

	@ManyToOne
	@JoinColumn(name = "user_id")
	private User user;
	
	@ManyToOne
	@JoinColumn(name = "issue_id")
	private Issue issue;
	
	@ManyToOne
	@JoinColumn(name = "project_id")
	private Project project;

	@Column(name = "hours")
	private Double time;

	private String comments;

	@Column(name = "spent_on")
	private Date date;
	
	@ManyToOne
	@JoinColumn(name = "activity_id")
	private Activity activity;

	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Issue getIssue() {
		return this.issue;
	}

	public void setIssue(Issue issue) {
		this.issue = issue;
	}

	public Project getProject() {
		return this.project;
	}

	public void setProject(Project project) {
		this.project = project;
	}

	public Double getTime() {
		return this.time;
	}

	public void setTime(Double time) {
		this.time = time;
	}

	public String getComments() {
		return this.comments;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}

	public Date getDate() {
		return this.date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public Activity getActivity() {
		return this.activity;
	}

	public void setActivity(Activity activity) {
		this.activity = activity;
	}

	public int compareTo(SpentTime o) {
		int project = this.project.compareTo(o.project);
		int user = this.user.compareTo(o.user);
		int date = this.date.compareTo(o.date);
		
		return project != 0 ? project : user != 0 ? user : date;
	}
}
